package com.store.application.impl.tests;

import static org.junit.Assert.*;

import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;

import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.store.application.Company;
import com.store.application.Order;
import com.store.application.Store;
import com.store.business.CompanyInDatabase;

public class RechercheOrdreParDateTest {
	
	EntityManager entityManager;
	Store store;
	Date date;
	

	@SuppressWarnings("static-access")
	@Before
	public void init() {
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		EntityManagerFactory entityManagerFactory = (EntityManagerFactory) context.getBean("entityManagerFactory");
		entityManager = entityManagerFactory.createEntityManager();
		
		store =  (Store)context.getBean("store");
		
		date.UTC(2014, 03, 20, 0, 0, 0);
		
		
	}

	@Test
	public void test() {
		// 
		List<Order> orders;
		try {
			orders = store.getOrderByDate(new Date(2014,03,20,0,0,0));
			assertEquals(orders.get(0).getDate(),date);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}

}
